<template>
    <el-dialog v-model="isShow" title="添加案例" draggable destroy-on-close append-to-body>
        <div class="flex_str_str itemSty">
            <div class="nameSty">案例图片:</div>
            <el-upload action="" v-model:file-list="yskjfileList" list-type="picture-card" :http-request="yskjUpdate"
                :multiple="true" limit="6" :before-remove="handleRemoveImg">
                <el-icon>
                    <Plus />
                </el-icon>
            </el-upload>
        </div>
        <div class="flex_str_str itemSty">
            <div class="nameSty">案例描述:</div>
            <textarea v-model="params.caseDesc" class="itpSty"></textarea>
        </div>
        <template #footer>
            <span class="dialog-footer">
                <el-button @click="cancel">取消</el-button>
                <el-button type="primary" @click="submitFun">
                    确定
                </el-button>
            </span>
        </template>
    </el-dialog>
</template>
<script lang="ts" setup>
import { reactive, ref, toRefs } from 'vue'
import { saveDesignApi, updateFileApi, addDesignAnLiApi } from '@/api/index/index'
import { ElMessage, ElLoading } from 'element-plus';
import type { UploadUserFile } from 'element-plus'
import { Plus } from '@element-plus/icons-vue'
const props = defineProps({
    isShow: {
        type: Boolean,
        defaul: false
    },
    id: {
        type: String || Number,
        default: null
    }
})
const emit = defineEmits(['close'])
const { isShow, id } = toRefs(props)
const params = reactive({
    designId: '',
    caseDesc: '',
    imageIds: ''
})

const yskjfileList = ref<UploadUserFile[]>([
])
// 原始框架图片上传
const yskjUpdate = (uploadFile: any) => {
    const loading = ElLoading.service({
        lock: true,
        text: '上传中...',
        background: 'rgba(0, 0, 0, 0.7)',
    })
    const file = uploadFile.file;
    const formData = new FormData();
    formData.append("file", file);
    updateFileApi(formData).then((res: any) => {
        loading.close()
        params.imageIds += res.data.fileId + ','
    })
}
const handleRemoveImg = (e: any) => {
    console.log(e)
}
const cancel = () => {
    emit('close')
}
const submitFun = () => {
    params.designId = id.value
    addDesignAnLiApi(params).then((res: any) => {
        if (res.status == 200) {
            ElMessage.success(res.message)
            emit('close')
        }
    })
}

</script>
<style scoped>
.textSty {
    width: 400px;
    height: 170px;
    resize: none;
}

.dialog-footer button:first-child {
    margin-right: 10px;
}

.nameSty {
    width: 130px;
}

.itpSty {
    width: 400px;
    min-height: 100px;
}

.itemSty {
    margin: 10px 0;
}
</style>